﻿using System;
using System.Collections.Generic;
using System.Text;
using YouHP.Utility;
using YouHP.Model.Group;
using YouHP.BLL;
using System.Web;

namespace YouHP.Pages.Group
{
   public class Member:GroupBasePage
    {

        protected List<GroupUserInfo> GroupUserList =new List<GroupUserInfo>();
        protected List<GroupUserInfo> mGroupAdminList = new List<GroupUserInfo>();
        protected List<GroupUserInfo> mGroupActivestList = new List<GroupUserInfo>();
        protected int n;
        protected int _pageSize =10;
        protected int _pageIndex =1;
        protected int _pageCount = 0;
        protected int _firstpage = 1;
        protected int _prevpage;
        protected int _nextpage;
        protected int _mCount;
        protected string RoleName = "成员";
        protected string state;
        protected string creattime;
        protected string PagingString;
       protected override void ShowPage()
       {
           base.ShowPage();
           this.AddLocation("病友小圈子", "/Group/Index.aspx");
           this.AddLocation(GroupData.GroupName, "/Group/Member.aspx?gid={gid}");


           if (ErrorCount != 0)
           {
               return;
           }
           else
           {
               // 取得小圈子的详细数据
               gid = RequestTools.GetInt("gid", 0);
               if (gid <= 0)
               {
                   this.AddErrLine("找不到圈子");
                   return;
               }
               GroupData = GroupBLL.Instance.GetGroupInfo(gid);
               if (GroupData.Id <= 0)
               {
                   this.AddErrLine("找不到圈子");
                   return;
               }

               if (UserData.Id > 0)
               {
                   GroupUserData = GroupUserBLL.Instance.GetGroupUserInfo(gid, UserData.Id);
               }

               if (GroupUserData.Role == Utility.Constants.RoleAdmin || GroupUserData.Role == Utility.Constants.RoleCreator ||
                GroupUserData.Role == Utility.Constants.RoleMember || GroupUserData.Role == Utility.Constants.RoleBlacklist)
                   state = "欢迎你！";  //已是圈中成员
               else if (GroupUserData.Role == Utility.Constants.RoleAppling) state = "正在等待审核中"; //等待审核
               else state = "申请加入该圈"; //不是圈中成员

               //管理员列表
               mGroupAdminList = GroupUserBLL.Instance.GetGroupUserListAdmin(gid);
               //圈子最活跃用户列表
               mGroupActivestList = GroupUserBLL.Instance.GetGroupUserListActivest(gid, n);

               _pageIndex = RequestTools.GetQueryInt("page", 1);
               //成员列表
               GroupUserList = GroupUserBLL.Instance.GetGroupUserList(gid, _pageSize, _pageIndex, out _mCount);
 
               _pageCount = Utils.GetPageCount(_mCount, 5);

               string query = HttpContext.Current.Request.Url.Query;
               query = Utils.RemoveQueryItem(query, "page");

               PagingString = this.GetPagingString(_pageIndex, _pageCount,
                   "/Group/Member.aspx" + query, "page");
           }
         }
    }
}
